layui.config({
	base : "js/"
}).use(['form','layer','jquery','laypage'],function(){
	var form = layui.form(),
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
		$ = layui.jquery;

	let pageInfo = {
		pageNumber: 0,
		pageSize: 2,
		mechanismList: [],
		pageTotal: 0,
		total: 1,
		firstPage: 1,
		lastPage: 1,
		prevPage: 1,
		nextPage: 2,
		search: ""
	};
	new Vue({
		el:"#app",
		data: {
			page: pageInfo,
			search: pageInfo.search
		},
		mounted: function () {
			this.getList();
		},
		methods: {
			getList: function () {
				let word = $("input[name='search']").val();
				let postData = new URLSearchParams();
				postData.append("pageNumber",pageInfo.pageNumber);
				postData.append("pageSize",pageInfo.pageSize);
				postData.append("search",word);
				axios({
					method: 'post',
					url: 'http://localhost/manage/mechanismList',
					data: postData
				}).then((res) => {
					//数据显示
					pageInfo.total = res.data.page.total;
					pageInfo.pageNumber = res.data.page.pageNumber;
					pageInfo.pageSize = res.data.page.pageSize;
					pageInfo.pageTotal = res.data.page.pageTotal;
					pageInfo.firstPage = res.data.page.firstPage;
					pageInfo.lastPage = res.data.page.lastPage;
					pageInfo.prevPage = res.data.page.prevPage;
					pageInfo.nextPage = res.data.page.nextPage;
					pageInfo.mechanismList = res.data.page.dataList;
					pageInfo.search = res.data.search;
				})
			},
			pageNext: function () {
				if(pageInfo.pageNumber<pageInfo.pageTotal){
					pageInfo.pageNumber+=1;
				}else{
					layer.msg("已是最后一页");
				}
				this.getList();
			},
			pagePrev: function () {
				if(pageInfo.pageNumber>1){
					pageInfo.pageNumber--;
				}else{
					layer.msg("当前是第一页")
				}
				this.getList();
			},
			homePage: function () {
				pageInfo.pageNumber=0;
				this.getList();
			},
			lastPage: function () {
				pageInfo.pageNumber=pageInfo.pageTotal;
				this.getList();
			}

		}
	});


	function usersList() {
		//渲染数据
		function renderDate(data, curr) {
			var dataHtml = '';
			currData = usersData.concat().splice(curr * nums - nums, nums);
			if (currData.length != 0) {
				for (var i = 0; i < currData.length; i++) {
					dataHtml += '<tr>'
						+ '<td><input type="checkbox" name="checked" lay-skin="primary" lay-filter="choose"></td>'
						+ '<td>' + currData[i].userName + '</td>'
						+ '<td>' + currData[i].userEmail + '</td>'
						+ '<td>' + currData[i].userSex + '</td>'
						+ '<td>' + currData[i].userGrade + '</td>'
						+ '<td>' + currData[i].userStatus + '</td>'
						+ '<td>' + currData[i].userEndTime + '</td>'
						+ '<td>'
						+ '<a class="layui-btn layui-btn-mini users_edit"><i class="iconfont icon-edit"></i> 编辑</a>'
						+ '<a class="layui-btn layui-btn-danger layui-btn-mini users_del" data-id="' + data[i].usersId + '"><i class="layui-icon">&#xe640;</i> 删除</a>'
						+ '</td>'
						+ '</tr>';
				}
			} else {
				dataHtml = '<tr><td colspan="8">暂无数据</td></tr>';
			}
			return dataHtml;
		}
	}

});